#include "ysqd.h"


int main() {
    WelcomeLoading();
    prepare();
    UsageHint();

    int recv;
    printf("\n请输入指令码(-1重新显示指令码): ");
    fflush(stdout);
    scanf("%d", &recv);    
    while (recv == -1) {
        UsageHint();
        printf("\n请输入指令码(-1重新显示指令码): ");
        fflush(stdout);
        scanf("%d", &recv);
    }

    while (1 <= recv && recv <= sizeof(commands)/sizeof(char*)) {
        float mean, std_devi;
        printf("=> 当前算法: %s\n", commands[recv]);
        call_fns[recv](numbers, FLOAT_NUMBERS, &mean, &std_devi);
        printf("\n请输入指令码(-1重新显示指令码): ");
        fflush(stdout);

        do {
            scanf("%d", &recv);
            if (recv != -1) {
                break;
            }
            UsageHint();
            printf("\n请输入指令码(-1重新显示指令码): ");
            fflush(stdout);
        } while (1);    
    }
    printf("==> •:*´拜拜`*:•");
}

void prepare() {
    FILE * f = NULL;
    f = fopen("dataset.txt", "wb+");
    if (f == NULL) {
        printf("\n[ERROR] create file failed: %s", strerror(errno));
        return;
    }
    
    srand((unsigned int)time(NULL));
    for (int i = 0; i < FLOAT_NUMBERS; i++) {
        numbers[i] = (float)rand()/RAND_MAX;
        char str[100];
        sprintf(str, "%.3f,", numbers[i]);
        fputs(str, f);
    }
    fclose(f);
}